#include "usart_dma.h"
#include "dma.h"
#include "usart.h"
#include "string.h"

UsartIdleT usartIdle3_t;
UsartIdleT usartIdle4_t;
UsartIdleT usartIdle5_t;

void usrtdmaIdleRecInit(UART_HandleTypeDef* huart,UsartIdleT* typ_uart)
{
	typ_uart->recved_flag = 0;
	typ_uart->rx_len = 0; 
	__HAL_UART_ENABLE_IT(huart, UART_IT_IDLE);
	HAL_UART_Receive_DMA(huart,typ_uart->rx_buf,BUF_SIZE); 
}

void usrtdmaRec(UART_HandleTypeDef* huart,UsartIdleT* typ_uart,DMA_HandleTypeDef* hdma_usart_rx)
{
	uint32_t tmp_flag = 0;
	uint32_t temp;
	tmp_flag =__HAL_UART_GET_FLAG(huart,UART_FLAG_IDLE);
	if((tmp_flag != RESET)){
		__HAL_UART_CLEAR_IDLEFLAG(huart);
		HAL_UART_DMAStop(huart); 
		temp = hdma_usart_rx->Instance->NDTR;
		typ_uart->rx_len = BUF_SIZE - temp;
		typ_uart->recved_flag = 1;
		HAL_UART_Receive_DMA(huart,typ_uart->rx_buf,BUF_SIZE);
	 }
}

